class Solution {
public:
    bool IsPopOrder(vector<int> pushV, vector<int> popV) {
        stack<int> st;
        int i = 0;
        int j = 0;
        while (i < pushV.size())
        {
            if (!st.empty() && st.top() == popV[i])
            {
                ++i;
                st.pop();
            }
            else
                st.push(pushV[j++]);
        }
        return i == j;
    }
};